Id like to add my own menu of few links to the page. It is gonna be hardcoded into the page.tp.php file

Id like class ACTIVE to work like on any other dynamic drupal menu.

Is there a way of getting class="active" from the script somehow to add into hand made menu.

How shoould I do it?

Thanks for help and ideas.

Mike

Comments

nevets’s picture

Under "Administer" -> "Site building" -> "Menus" you can add your own menus.

misiu9’s picture

I now that I can do it but this is a differebt question.

I have to build the menu myself and hardcode into my template. it can not be any of dynamic - automatic created menus.

Is there a way of getting CLASS="ACTIVE" to be implemented...

What function does it for primary links??

Which parameter should I put into my template to get CLASS="ACTIVE" when the link should be active ??

Thanks

Mike

vm’s picture

it's done in .css you can find the declaration using firebug addon for firefox and working backwards.
_____________________________________________________________________
Confucius says:
"Those who seek drupal answers should use drupal search!" : )

misiu9’s picture

I now that I can do it but this is a different question.

I dont think its CSS either. It has to be called by some php function which checks the url of the page and compare to available links. How would you do that with css ??

I have to build the menu myself and hardcode into my template. it can not be any of dynamic - automatic created menus.

That is gonna be my only menu (no primary links or other navigation on the page)

I have to do it by hand because it is not a list or line of links. Its going around the page in a very custom
way ;)

Is there a way of getting CLASS="ACTIVE" to be implemented...

What function does it for primary links?? Is it gonna work if primary are hidden?

Which parameter should I put into my template to get CLASS="ACTIVE" when the link should be active ??

Thanks for all your answers and help

Mike

nevets’s picture

This is untested but I think it will help. Note this requires you pass it a valid Drupal path (ie one know by the menu system and unaliased).
So add this function to your template.php file

function is_path_active($path) {
  $menu = menu_get_menu();

  // Determine the menu item containing the callback.

  while ($path && !isset($menu['callbacks'][$path])) {
    $path = substr($path, 0, strrpos($path, '/'));
  }

  if (!isset($menu['callbacks'][$path])) {
    return FALSE;
  }
  
  $mid = $menu['path_index'][$path];
  
  return menu_in_active_trail($mid);
 }

And in you page.tpl.php you can do something like.

<?php
$path = 'Your path';
if ( is_path_active($path) ) {
  $attr = array('class' => 'active');
}
print l('Menu text', $path, $attr);
?>
misiu9’s picture

How can I get you a beer??

This is amazing. Thanks a lot !!!!

That works perfect. It is tested and implemented.

Thanks again

Mike

nevets’s picture

If you want other attributes other than class you can change

<?php
$path = 'Your path';
if ( is_path_active($path) ) {
  $attr = array('class' => 'active');
}
print l('Menu text', $path, $attr);
?>

to something like

<?php
$path = 'Your path';
$attr['title'] = 'Some title for your link';
if ( is_path_active($path) ) {
  $attr['class'] = 'active';
}
print l('Menu text', $path, $attr);
?>
misiu9’s picture

great help

that solved my problem..

thanks again

Mike